package com.overoid.diary.ui;

import com.overoid.diary.R;
import com.overoid.diary.ui.common.ActivityImpl;

import android.content.Context;
import android.content.Intent;

import android.net.Uri;
import android.os.Bundle;

import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;

import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.AdapterView;
import android.widget.VideoView;


public class VideoActivity extends ActivityImpl implements
		AdapterView.OnItemSelectedListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.video);

		final Button picBtnDone = (Button) findViewById(R.id.picBtnDone);
		picBtnDone.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Toast.makeText(VideoActivity.this, "btn cancle",
						Toast.LENGTH_SHORT).show();
				Intent in = new Intent(VideoActivity.this, DayActivity.class);
				startActivity(in);

			}
		});

		/*
		 * vSwitcher = (VideoSwitcher) findViewById(R.id.switcher);
		 * vSwitcher.setFactory(this);
		 * vSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
		 * android.R.anim.fade_in));
		 * vSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
		 * android.R.anim.fade_out));
		 */
		Gallery g = (Gallery) findViewById(R.id.gallery);
		g.setAdapter(new ImageAdapter(this));
		g.setOnItemSelectedListener(this);

	}

	public void onNothingSelected(AdapterView parent) {
	}

	public void onItemSelected(AdapterView parent, View v, int position, long id) {

		VideoView video = (VideoView) findViewById(R.id.switcher);
		// video.setVideoP("res/raw/vidoo.3gp");
		// video.setLayoutParams(new ViewSwitcher.LayoutParams(280,320));
		video.setVideoURI(Uri.parse(mImageIds[position]));
		MediaController nc = new MediaController(this);
		nc.setMediaPlayer(video);
		video.start();
		// vSwitcher.setVideoURI(Uri.parse(mImageIds[position]));*/
	}

	public class ImageAdapter extends BaseAdapter {
		public ImageAdapter(Context c) {
			mContext = c;
		}

		public int getCount() {
			return mThumbIds.length;
		}

		public Object getItem(int position) {
			return position;
		}

		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {

			ImageView i = new ImageView(mContext);

			i.setImageResource(mThumbIds[position]);
			i.setAdjustViewBounds(true);
			i.setLayoutParams(new Gallery.LayoutParams(
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
			// i.setBackgroundResource(R.drawable.picture_frame);
			return i;
		}

		private Context mContext;

	}

	private Integer[] mThumbIds = { R.drawable.alram_52x52,
			R.drawable.alram_52x52, R.drawable.hiraita_480x420,
			R.drawable.ddd_ghdry125_rlagkstjd05 };
	// R.drawable.hiraita_480x420,
	// R.drawable.alram_52x52,R.drawable.hiraita_480x420,
	// R.drawable.alram_52x52,R.drawable.hiraita_480x420,
	// R.drawable.alram_52x52,R.drawable.hiraita_480x420,
	// R.drawable.alram_52x52,R.drawable.hiraita_480x420,
	// R.drawable.alram_52x52,R.drawable.hiraita_480x420,
	// R.drawable.alram_52x52};

	private String[] mImageIds = {
			"http://kickyoutube.com/download/26750318/KickYouTube%20-%20Download%20videos%20from%20youtube.3gp",
			"http://kickyoutube.com/download/26781537/Gunther-ding%20ding%20dong.3gp",
			"http://kickyoutube.com/download/26750318/KickYouTube%20-%20Download%20videos%20from%20youtube.3gp" };
	// {R.drawable.alram_52x52,R.drawable.hiraita_480x420 ,
	// R.drawable.alram_52x52,R.drawable.hiraita_480x420,
	// R.drawable.alram_52x52,R.drawable.hiraita_480x420,
	// R.drawable.alram_52x52,R.drawable.hiraita_480x420,
	// R.drawable.alram_52x52,R.drawable.hiraita_480x420,
	// R.drawable.alram_52x52,R.drawable.hiraita_480x420,
	// R.drawable.alram_52x52};

}
